/*
package com.ruiyi.subway.utils;



import com.ruiyi.subway.exception.BusinessException;

import java.util.*;

*/
/**
 * Created by jiangshicun on 2017/10/16.
 *//*

public class EncryptUrlUtils {
    private final static String tenant = "test_yuan";
    private final static String key = "bcvLtwpHDmMC6qBfqVCGKzCrAp4FhB";
    //配置文件
    private final static long expireTime = 600000;

    */
/**
     * 生成URL
     *
     * @param params
     * @param url
     * @return
     * @throws Exception
     *//*

    public static String encryptUrl(Map<String, String> params, String url) throws Exception {
        String requestUrl = constructRequestUrl(params, url);
        String token = generateToken(params);
        return (requestUrl + "token=" + token);
    }

    private static String generateToken(Map<String, String> params) throws Exception {
        String md5 = EncryptUrlUtils.getOriginMd5(params);
        return EncryptUtil.encryptAES(md5, key.substring(0,16));
    }

    private static String constructRequestUrl(Map<String, String> params, String url) {
        Long time = new Date().getTime();
        params.put("timestamp", Long.toString(time));
        params.put("tenant", tenant);
        for (Map.Entry<String, String> entry : params.entrySet()) {
            url = url + entry.getKey() + "=" + entry.getValue() + "&";
        }
        return url;
    }

    */
/*private static String getOriginMd5(Map<String, String> map) throws Exception {
        if (map.size() == 0) {
            throw new Exception("传入参数为空");
        }
        return EncryptUtil.encryptMD5(sort(map));  //MD5加密
    }*//*


    private static String sort(Map<String, String> map) {
        List<String> list = new ArrayList<>();
        for (Map.Entry<String, String> entry : map.entrySet()) {
            list.add(entry.getKey() + "=" + entry.getValue());
        }
        Collections.sort(list);
        String encryptStr = "";
        for (String str : list) {
            encryptStr = encryptStr + str;
        }
        return encryptStr;
    }

    */
/**
     * 校验
     *
     * @param token
     * @param paramMap
     * @return
     * @throws Exception
     *//*

    public static void checkRequestUrl(String token, Map<String, String> paramMap, String key)
            throws Exception {
        if (paramMap.size() == 0 || token == null) {
            throw new BusinessException("传入参数为空");
        }
        if (new Date().getTime() - Long.parseLong(paramMap.get("timestamp")) > expireTime) {
            throw new BusinessException("请求已超时，请重新生成链接");
        }
        if (!getInputMd5(token, key).equals(getOriginMd5(paramMap))) {
            throw new BusinessException("令牌校验失败");
        }
    }

    private static String getInputMd5(String token, String key) throws Exception {
        return EncryptUtil.decryptAES(token, key.substring(0,16));
    }

    public static void main(String args[]) {
        Map<String, String> map = new HashMap();
        map.put("title", "hhhjj");
        map.put("hasOriginal", "true");
        try {
            String url = encryptUrl(map, "http://192.168.0.196:7080/vcs/resources/transactions.html?");
            System.out.println(url);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
*/
